package com.luoy.obs;


import com.obs.services.ObsClient;
import com.obs.services.ObsConfiguration;
import com.obs.services.model.AuthTypeEnum;
import com.obs.services.model.ListBucketsRequest;
import com.obs.services.model.ObsBucket;

import java.util.List;


/**
 * @desc:
 * @author: luoy
 * @date: 2022-09-02 15:17
 */
public class OssUtil1 {

    //@Value("${oss.backend.url}")
    //  private  static String endPoint="http://172.22.1.7:7333/";
    private  static String endPoint="http://172.22.1.7:7333/";
    private static String ak = "oss001";
    private static String sk = "12345678";


    public void setUrl(String url) {
        endPoint = url;
    }




    public static void createBucket() {

        ObsBucket luoy1 = getObsClient().createBucket("luoy1");


    }

    public static void main1(String[] args) {
        list();
    }

    public static ObsClient getObsClient() {
        //  System.out.println(s);
        ObsConfiguration obsConfiguration = new ObsConfiguration();
        obsConfiguration.setAuthType(AuthTypeEnum.OBS);
        obsConfiguration.setEndPoint(endPoint);
        ObsClient obsClient = new ObsClient(ak, sk,obsConfiguration);

        return obsClient;
    }

    public static void list() {
        // 列举桶
        ListBucketsRequest request = new ListBucketsRequest();
        request.setQueryLocation(true);
        List<ObsBucket> buckets = getObsClient().listBuckets(request);
        for (ObsBucket bucket : buckets) {
            System.out.println(bucket);
        }
        ObsClient obsClient = getObsClient();


        boolean b = obsClient.headBucket("limd-test");

        System.out.println(b);
       //ddddd
        //22
    }

}
